Repository navigation
refactor(grid3d): the 3D views are split into a pure core, ports and adapters, and can go fullscreen and be retitled - #87
Merged
Conversation
…e modules The parts of view.py and web.py that touch nothing outside Python were moved, nearly verbatim, into their own modules: - errors.py: Unavailable - geometry.py: ViewGeometry, with the sun direction and near/far planes both views send to Strata - wire.py: the grid relay's wire format 1.0 (encoders, decode, readHeader, WireError, limits), byte for byte as before - events.py: the event types, Event, pygameKey and toPygameEvents - state.py: ViewState, the board, pieces, animator and HUD that Grid3DView and Grid3DWebView each kept in their own copy; each view now calls its steps in the order it did before view.py and web.py re-export every name they had, as the same objects, so grid3d.view and grid3d.web import as before. No behaviour was changed. drafted by Claude on behalf of Daniel Stephenson Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01LYNeuoCqxFpUXrFhxnTg89
…act tests Six ports were added under grid3d/ports/, one interface per file, each with its contract in its doc comment: - SceneRenderer: draw one complete Scene now - EventSource: the input since the last poll - Surface: resize, savePng, close - StrataLoader: open a Strata engine here, or say why not - GridRelay: the page's grid relay (its own six-call JS API) - PageObjects: the page's JS objects by name test_grid3d_ports.py runs each contract against a fake. The same contracts run against the production adapters once they exist (their cases skip until then). No behaviour was changed. drafted by Claude on behalf of Daniel Stephenson Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01LYNeuoCqxFpUXrFhxnTg89
The code that talks to Strata, the page and pygbag was moved, nearly verbatim, into grid3d/adapters/: - BindingStrataLoader: loadStrata, the pinned STRATA_VERSION, the SDL and Gallium defaults, the engine, its lighting and sun - StrataEngine: drawing a Scene through the binding (renderItems, labelBytes), polling, resize, savePng, close - RelayDisplay: drawing a Scene as relay messages (only what changed), sending, Event polling, the savePng refusal - PlatformRelay, RecordingRelay: the two GridRelays - PygbagPageObjects: window.<name> under pygbag Grid3DView and Grid3DWebView now delegate to them and keep every attribute games and tests read (view.strata, view.lib, view.engine, view.relay, view.sent, view.lastSent), as properties. view.py and web.py re-export every moved name. The port contracts now run against these adapters as well as the fakes. No behaviour was changed. drafted by Claude on behalf of Daniel Stephenson Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01LYNeuoCqxFpUXrFhxnTg89
Grid3DView now draws, polls, resizes, saves and closes through whatever display it is given: Grid3DView.using(display, ...) takes any SceneRenderer, EventSource and Surface whose `strata` names the event types, and the old constructor wraps the binding in a StrataEngine as before. The page helpers (wants3D, set3D, buttonArea, touchScreen, pageObject) and Grid3DWebView.open read the page through web.PAGE, a PageObjects, and PlatformRelay takes the page it looks in. test_grid3d_core.py drives both views over fakes of their ports, with no stand-in strata module and no patched sys.platform. No behaviour was changed. drafted by Claude on behalf of Daniel Stephenson Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01LYNeuoCqxFpUXrFhxnTg89
…roots The production wiring was put in one place per view, as defaults: view.STRATA_LOADER (a BindingStrataLoader) opens the desktop engine for Grid3DView.open(), read at each call so a test or tool can swap it, and web.PAGE plus PlatformRelay are what Grid3DWebView.open() and the page helpers use. Both modules' docstrings now say how they are wired. A test opens a Grid3DView through a fake loader. No behaviour was changed. drafted by Claude on behalf of Daniel Stephenson Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01LYNeuoCqxFpUXrFhxnTg89
…p their names The wire-format and render tests now import the encoders from wire.py and renderItems / labelBytes from adapters/strata_engine.py, where they live; their assertions are unchanged. grid3d.view and grid3d.web are kept as re-export shims, since code outside this repository imports from them (ophidian, apex, Tic-Tak-Toe). test_grid3d_shims.py checks every name either module had in 0.5.3 is still there, as the same object as its new home, except the private _NoBoard stand-in, which moved into RelayDisplay. view also keeps Animator and the picking functions it used to import. No behaviour was changed. drafted by Claude on behalf of Daniel Stephenson Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01LYNeuoCqxFpUXrFhxnTg89
…g into the engine Grid3DView.setFullscreen(enabled) and setTitle(title) were added, so games can stop calling view.engine.set_fullscreen / set_title and view.lib.has themselves (apex and ophidian do today; view.strata, view.lib and view.engine keep working). They return True when done and False when the loaded Strata lacks the call (0.8.0 has no strata_set_title), the view is closed, or, for fullscreen, the view is headless, where Strata would raise. Grid3DWebView has both and always returns False: the browser owns its window and the page its title. They sit on a new WindowChrome port, implemented by StrataEngine and RelayDisplay and covered by the port contract tests. A pollEvent() was not added: pollEvents() already drains the engine the way the games' own loops do. drafted by Claude on behalf of Daniel Stephenson Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01LYNeuoCqxFpUXrFhxnTg89
test_grid3d_architecture.py walks every model, core and port module with ast and fails when one imports an adapter or a composition root (view, web, relay), resolving relative imports the way Python does, and fails when a port or adapter file holds more than one class. A test feeds it a violating file, so a walk that sees nothing can't pass unnoticed. drafted by Claude on behalf of Daniel Stephenson Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01LYNeuoCqxFpUXrFhxnTg89
…documented docs/grid3d.md gained a "How the views are built" section (the layers, the port and adapter table, the architecture and contract tests, and how to add a backend: one adapter file plus a registry entry), rows for setFullscreen, setTitle, view.strata / lib / engine, Grid3DView.using and web.PAGE, and PlatformRelay's page argument. The package docstring carries the same diagram, and test.yml's comment says where STRATA_VERSION now lives. drafted by Claude on behalf of Daniel Stephenson Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01LYNeuoCqxFpUXrFhxnTg89
grid3d now has subpackages (ports/, adapters/). The archive-install job imported only the top-level package, so a build that dropped them would have passed. It now imports grid3d's adapters, ports and web from the installed copy and checks the pygbag page template is there. drafted by Claude on behalf of Daniel Stephenson Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01LYNeuoCqxFpUXrFhxnTg89
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
The grid3d views (
Grid3DViewon Strata's Python binding,Grid3DWebViewover pygbag and thepage's grid relay) were restructured into a pure core plus ports and adapters, one interface or
implementation per file. Behaviour is unchanged, and every name importable today stays
importable. Two window calls were added so games can stop reaching into the engine. This PR is
stacked on the test-only PR that pins the views' seams; that one merges first.
This was approved as a port map beforehand. Per the owner's decisions,
relay.py, the pygbagtemplate and its JS are untouched; the
clock=callable stays as the clock seam; the desktop andweb event shapes stay as they are. It merges untagged and ships with 0.6.0.
Layout
StrataLoaderBindingStrataLoaderSceneRendererStrataEngine,RelayDisplayEventSourceStrataEngine,RelayDisplaySurfaceStrataEngine,RelayDisplayWindowChromeStrataEngine,RelayDisplayGridRelayPlatformRelay,RecordingRelayPageObjectsPygbagPageObjectsNew API
view.setFullscreen(enabled)andview.setTitle(title)returnTruewhen done andFalsewhen they can't: the loaded Strata lacks the call (0.8.0 has no
strata_set_title), the view isclosed, or, for fullscreen, the view is headless (Strata raises there). On
Grid3DWebViewbothalways return
False. apex and ophidian can move to these later;view.strata,view.libandview.enginekeep working.Grid3DView.using(display, ...)builds a view over any display with the ports, for tests and tools.view.STRATA_LOADERandweb.PAGEare the composition roots' defaults; tests can swap them.PlatformRelay(relay=None, page=None)takes the page it looks in.pollEvent()was not added:pollEvents()already drains the engine the way the games' loops do.Visible differences (no behaviour change, but worth knowing)
Unavailableis defined ingrid3d.errors, so tracebacks printpreponderous.graphik.grid3d.errors.Unavailable. It is the same class object under every oldname.
view.strata,view.lib,view.engine,webView.relay,webView.sentandwebView.lastSentare now read-only properties: reading them is unchanged, assigning to them raises.
view.STRATA_VERSIONorview.loadStratano longer changes whatopen()loads;they live in
adapters/binding_strata_loader.py, andview.STRATA_LOADERis the seam now.web._NoBoard/web._NO_BOARDstand-in moved intoRelayDisplay.Commits (one per step)
Test plan
strata-engine0.8.0, Node present, so the template JS testsrun): 534 → 703 passed, 0 skipped, 0 failed; same with
GRAPHIK_REQUIRE_STRATA=1GRAPHIK_REQUIRE_STRATA=1): 353 → 522 passed;golden board image and frame-cost tests green
job); the grid3d sources parse with 3.9 grammar
parity.pywith one driver per side against each tree (each side imports its own tree):labels, viewports, merged tiles, tints)
engine call and every relay message byte)
golden/wire-1.0.hexis unchanged and its test passesweb.→wire.,view.renderItems→adapters.strata_engine); after normalising those, the old and newassertion lines are identical. Test count only went up.
check_layers.pyreports 0 problems, and newtest_grid3d_architecture.pyenforces the same rule in CI (verified to catch an injectedviolation)
test.yml):adapters/,ports/and the templateinstall, and the CI job now checks them
per frame each; the time is raster, not Python)
the same counts on 0.5.3 and on this branch:
ophidian 804 passed, 2 skipped (both skips are the game's own, the same on both); apex 746
passed; Tic-Tak-Toe 376 passed
graphik; the
adapters/andports/files are insrc.apk. Its Playwright e2e (phone anddesktop; 3D, 2D, win/loss/tie, falling back to 2D) passed 151/151 on a second run. The first
run had 2 timing misses: the HUD check on the desktop loss screen gave up, though the
screenshot taken just after shows the loss screen drawn correctly. That run overlapped
another browser job on the same machine. The existing 0.5.3 build passed 161/161 with the
same harness (its game branch has 10 more checks).
drafted by Claude on behalf of Daniel Stephenson
🤖 Generated with Claude Code